import {
  Body,
  Controller,
  Get, Param, ParseUUIDPipe, Post, Query,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { EvaluationService } from './evaluation.service';
import { EvaluationBatchDto, EvaluationBatchTitleDto, EvaluationIndexDto } from "@/module/evaluation/evaluation.dto";
import {
  EvaluationBatchResult,
  EvaluationBatchTitleResult,
  EvaluationIndexResult, EvaluationShowResult
} from "@/module/evaluation/evaluation.result";
import { ApiPaginatedOkResponse } from "@/common/pager-response/api-paginated-ok-response.decorator";
import { PageResult } from "common/interface";
import { getPager } from "@/common/pager-response";

@Controller('/v1/evaluations')
@ApiTags('Evaluation')
export class EvaluationV1Controller {
  constructor(private readonly evaluationService: EvaluationService) {
  }

  @Post('/')
  @ApiOperation({ summary: '列表' })
  @ApiPaginatedOkResponse(EvaluationIndexResult)
  async index(
    @Body() body: EvaluationIndexDto,
  ): Promise<PageResult<EvaluationIndexResult>> {
    const res = await this.evaluationService.index(body);
    return getPager(...res);
  }

  @Get('/batch-title')
  @ApiOperation({ summary: '批量查标题' })
  @ApiOkResponse({ type: EvaluationBatchTitleResult, isArray: true })
  async batchTitle(@Query() query: EvaluationBatchTitleDto): Promise<EvaluationBatchTitleResult[]> {
    const res = await this.evaluationService.batchTitle(query);
    return res;
  }

  @Post('/batch')
  @ApiOperation({ summary: '批量通过uuid来获取' })
  @ApiOkResponse({ type: EvaluationBatchResult,isArray: true })
  async batch(
    @Body() body: EvaluationBatchDto,
  ): Promise<EvaluationBatchResult[]> {
    const res = await this.evaluationService.batch(body);
    return res;
  }

  @Get('/:uuid')
  @ApiOperation({ summary: '数据文章详情' })
  @ApiOkResponse({ type: EvaluationShowResult })
  async show(@Param('uuid', ParseUUIDPipe) uuid: string): Promise<EvaluationShowResult | null> {
    const res = await this.evaluationService.show(uuid);
    return res;
  }

}
